<?php
$orderIds = $this->getRequest()->getPost('order_ids');
$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', array('in' => array('pending', 'processing')))
    ->addFieldToFilter('entity_id', array('in' => $orderIds));
?>
<div class="content-header">
    <h3 class="icon-head head-sales-order-invoice">运单确认</h3>
    <p class="form-buttons">
        <button id="id_7ecf0ab045f01f0c1081d8dc04dc0e57" title="返回" type="button" class="scalable back"
                onclick="javascript:history.back()" style=""><span><span><span>返回</span></span></span></button>
    </p>
</div>
<div>
    <form action="<?php echo $this->getUrl('tms/adminhtml_shipping/create'); ?>" method="post" name="shipping_form"
          id="shipping_form">
        <?php echo $this->getBlockHtml('formkey') ?>
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-products">待创建的订单</h4>
            </div>
        </div>
        <div class="grid np">
            <div class="hor-scroll">
                <table cellspacing="0" class="data order-tables">
                    <colgroup>
                        <col width="1">
                        <col width="1">
                        <col width="1">
                        <col width="1">
                        <col>
                    </colgroup>
                    <thead>
                    <tr class="headings">
                        <th><span class="nobr">订单排序</span></th>
                        <th>订单号</th>
                        <th><span class="nobr">订单总额</span></th>
                        <th><span class="nobr">收货人</span></th>
                        <th><span class="nobr">收货人电话</span></th>
                        <th class="last"><span class="nobr">收货地址</span></th>
                    </tr>
                    </thead>
                    <tbody class="even">
                    <?php foreach ($orders as $order): ?>
                        <?php $storeId = $order->getStoreId(); ?>
                        <tr class="border">
                            <td>
                                <input type="text" name="sort[<?php echo $order['entity_id'] ?>]"
                                       value="<?php echo $order['sort'] ?>" title="订单排序" style="width: 50px;"/>
                            </td>
                            <td><input type="hidden" name="order_ids[]"
                                       value="<?php echo $order->getId(); ?>"/><?php echo $order->getIncrementId(); ?>
                            </td>
                            <td><?php echo Mage::helper('checkout')->formatPrice($order->getGrandTotal()); ?></td>
                            <td><?php echo $order->getShippingAddress()->getFirstname(); ?></td>
                            <td><?php echo $order->getShippingAddress()->getTelephone(); ?></td>
                            <td><?php echo str_replace(" HHH", '', $order->getShippingAddress()->format('online')); ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>

        </br>
        <div class="clear"></div>
        <?php
        $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();
        $region = Mage::helper("tms")->getRegion($websiteId);
        $car = Mage::helper("tms")->getCar($websiteId);
        ?>
        <div class="box-left">
            <div class="entry-edit">
                <div class="entry-edit-head">
                    <h4 class="icon-head head-products">分拣区域</h4>
                </div>
                <fieldset>
	            <span class="field-row">
		            <label class="normal" for="history_comment">分拣区域</label>
		            <select id="region" name="region_id" class="required-entry select">
		            	<option></option>
                        <?php foreach ($region as $k => $value): ?>
                            <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
                        <?php endforeach; ?>
		            </select>
		        </span>
                </fieldset>
                <div class="entry-edit-head">
                    <h4 class="icon-head head-products">车载信息</h4>
                </div>
                <fieldset>
                <span class="field-row">
    	            <label class="normal" for="history_comment">车载编号</label>
    	 			<select id="car" name="car_id" class="required-entry select">
    	 				<option></option>
                        <?php foreach ($car as $k => $value): ?>
                            <option value="<?php echo $k; ?>"><?php echo $value; ?></option>
                        <?php endforeach; ?>
    	 			</select>
                </fieldset>
            </div>
        </div>
        <div class="box-right">
            <div class="entry-edit">
                <div class="entry-edit-head">
                    <h4 class="icon-head head-products">备注信息</h4>
                </div>
                <fieldset>
	            <span class="field-row">
		            <label class="normal" for="history_comment">备注</label>
		            <textarea name="history[comment]" rows="3" cols="5" style="height:6em; width:99%;"
                              id="history_comment"></textarea>
		        </span>
                </fieldset>
                <div class="order-totals">
                    <div class="order-totals-bottom">
                        <div class="a-right">
                            <button id="id_23868b56689ba3bbaca362b19f9dfb29" title="创建送货单" type="button"
                                    class="scalable save submit-button" onclick="check()" style=""><span><span><span>创建运单</span></span></span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

</div>
</div>
<script type="text/javascript">
    function check() {
        var region = jQuery("#region").children('option:selected').val();
        var car = jQuery("#car").children('option:selected').val();
        if (!region || !car) {
            alert("请选择分拣区域和车载编号");
            return false;
        } else {
            disableElements('submit-button');
            $('shipping_form').submit();
        }
    }
</script>